package strts.listener;

import java.util.Map;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import strts.util.StrutsParseXml;
import strts.util.XmlBean;

public class ActionListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
	
		System.out.println("系统已成功注销");

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		String xmlPath = arg0.getServletContext().getInitParameter("struts-config");
		String tomcatPath = arg0.getServletContext().getRealPath("/");
		
		try {
			//将配置文件转化为XmlBean的map对象，方便以后获取处理action和转发路径
			Map<String ,XmlBean> map = StrutsParseXml.ParseXml(tomcatPath + xmlPath);
			arg0.getServletContext().setAttribute("struts",map);

		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("系统已加载完成");
		}

	}

}
